#ifndef _EXTERNALMSG4XA_
#define _EXTERNALMSG4XA_

#include "../../fep/type.h"
#define XINAN_DEVICE_TYPE_LEN                               13
#define XINAN_MESSAGE_TYPE_LENGTH                           2
#define XINAN_MESSAGE_CODE_LENGTH                           2

//configuration command
#define XINAN_MESSAGE_TYPE_BS_CONFIG                        "02"
#define XINAN_MESSAGE_CODE_BS_CONFIG_REQUEST                "0201"
#define XINAN_MESSAGE_CODE_BS_CONFIG_RESPONSE               "02"

#define XINAN_MESSAGE_CODE_TX_TURNON_REQUEST                "0217"
#define XINAN_MESSAGE_CODE_TX_TURNON_RESPONSE               "18"

#define XINAN_MESSAGE_CODE_TX_TURNOFF_REQUEST               "0219"
#define XINAN_MESSAGE_CODE_TX_TURNOFF_RESPONSE              "20"
#define XINAN_MESSAGE_CODE_RF_CONFIG_REQUEST                "0215"
#define XINAN_MESSAGE_CODE_RF_CONFIG_RESPONSE               "16"

#define XINAN_MESSAGE_CODE_STATUS_REPORT                    "12"
#define XINAN_MESSAGE_CODE_STATUS_RESPONSE                  "0213"

#define XINAN_MESSAGE_CODE_BS_REBOOT_REQUEST                "0207"
#define XINAN_MESSAGE_CODE_BS_REBOOT_RESPONSE               "08"

#define XINAN_MESSAGE_CODE_QUERY_CONFIG_REQUEST             "0203"
#define XINAN_MESSAGE_CODE_QUERY_CONFIG_RESPONSE            "04"

#define XINAN_MESSAGE_CODE_TIME_CONFIG_REQUEST              "0242"
#define XINAN_MESSAGE_CODE_TIME_CONFIG_RESPONSE             "43"

#define XINAN_MESSAGE_CODE_ALARMUE_CONFIG_REQUEST           "0253" 
#define XINAN_MESSAGE_CODE_ALARMUE_CONFIG_RESPONSE          "54" 
#define XINAN_MESSAGE_CODE_ALARMUE_REPORT                   "55"
#define XINAN_MESSAGE_CODE_TIME_REQUEST                     "44" 
#define XINAN_MESSAGE_CODE_FTP_CONFIG_REQUEST               "0256"
#define XINAN_MESSAGE_CODE_FTP_CONFIG_RESPONSE              "57"
#define XINAN_MESSAGE_CODE_FTP_QUERY_REQUEST                "0258"
#define XINAN_MESSAGE_CODE_FTP_QUERY_RESPONSE               "59"
#define XINAN_MESSAGE_CODE_UPGRADE_REQUEST                  "0260"
#define XINAN_MESSAGE_CODE_QUERY_LOG                        "61"

#define XINAN_MESSAGE_CODE_DEVICE_REGISTER_REQUEST          "64" 
#define XINAN_MESSAGE_CODE_DEVICE_REGISTER_RESPONSE         "0265" 
#define XINAN_MESSAGE_CODE_DEVICE_SNIFFER_REQUEST           "0225" 
#define XINAN_MESSAGE_CODE_DEVICE_SNIFFER_RESPONSE          "0226" 
#define XINAN_MESSAGE_CODE_DEVICE_SNIFFER_CONFIG_REQUEST    "0222" 
#define XINAN_MESSAGE_CODE_DEVICE_SNIFFER_CONFIG_RESPONSE   "23" 
#define XINAN_MESSAGE_CODE_DEVICE_SNIFFER_RESULT            "24"

#define XINAN_MESSAGE_CODE_SSH_ON_REQUEST					"0231"
#define XINAN_MESSAGE_CODE_SSH_ON_RESPONSE					"32"
#define XINAN_MESSAGE_CODE_SSH_OFF_REQUEST					"0233"
#define XINAN_MESSAGE_CODE_SSH_OFF_RESPONSE					"34"
#define XINAN_MESSAGE_CODE_VERSION_SSH_QUERY				"0235"
#define XINAN_MESSAGE_CODE_VERSION_SSH_RESPONSE				"36"

//message success or failure
#define XINAN_MESSAGE_RESPONSE_CODE_SUCCESS                 "0"
#define XINAN_MESSAGE_RESPONSE_CODE_FAILURE                 "1"
                                                            
//device status                                             
#define XINAN_MESSAGE_STATUS_NORMAL                         "1"
#define XINAN_MESSAGE_STATUS_ABNORMAL                       "0"

#define XINAN_MESSAGE_HEADER_START                          "FFFF"
#define XINAN_MESSAGE_HEADER_LENGTH                         8
//some fix message body

#define XINAN_MESSAGE_BODY_AT                               "@"
#define XINAN_MESSAGE_BODY_SPACE                            " "
#define XINAN_MESSAGE_BODY_HASH                             "#"
#define XINAN_MESSAGE_BODY_COLON                            ":"

//WCDMA
#define XINAN_MESSAGE_BODY_PLMN                             "PLMN"
#define XINAN_MESSAGE_BODY_MCC                              "MCC"
#define XINAN_MESSAGE_BODY_MNC                   			"MNC"
#define XINAN_MESSAGE_BODY_LAC                   			"LAC"
#define XINAN_MESSAGE_BODY_RAC                   			"RAC"
#define XINAN_MESSAGE_BODY_CELLID                			"CELLID"
#define XINAN_MESSAGE_BODY_PSC                   			"PSC"
#define XINAN_MESSAGE_BODY_ARFCNo                			"ARFCN"

//LTE                                                            
#define XINAN_MESSAGE_BODY_TAC_CYCLE                        "TAC_CYCLE"
#define XINAN_MESSAGE_BODY_SYNC_MODE                        "SYNC_MODE"
#define XINAN_MESSAGE_BODY_BAND_WIDTH                       "BAND_WIDTH"
#define XINAN_MESSAGE_BODY_PCI                              "PCI"
#define XINAN_MESSAGE_BODY_UL_EARFCN                        "UL_EARFCN"
#define XINAN_MESSAGE_BODY_DL_EARFCN                        "DL_EARFCN"                                                            
#define XINAN_MESSAGE_BODY_PA                               "PA"
#define XINAN_MESSAGE_BODY_GA                               "GA"
#define XINAN_MESSAGE_BODY_GPS_DELAY                        "GPS_DELAY"                                                            
#define XINAN_MESSAGE_BODY_TAC                   			"TAC"

//GSM
#define XINAN_MESSAGE_BODY_MIN                              "reDetectMinute"
#define XINAN_MESSAGE_BODY_BAND                             "BAND"
#define XINAN_MESSAGE_BODY_ARFCN                            "ARFCN"                                                            
#define XINAN_MESSAGE_BODY_AUTOSNIFFER                      "AUTOSNIFFER"
#define XINAN_MESSAGE_BODY_CYCLE                            "CYCLE"
#define XINAN_MESSAGE_BODY_CONFIGMODE                       "CONFIGMODE"  

#define XINAN_MESSAGE_BODY_IP                               "IP:"
#define XINAN_MESSAGE_BODY_STATE                            "STATE:"                                                            
#define XINAN_MESSAGE_BODY_ID                               "ID:"                                                            
#define XINAN_MESSAGE_BODY_TAG                              "TAG:"       
                                                     
#define XINAN_MESSAGE_BODY_IMSI                             "IMSI:"                                                            
#define XINAN_MESSAGE_BODY_IMEI                             "IMEI:"    

#define XINAN_MESSAGE_BODY_FDD                              "FDD"
#define XINAN_MESSAGE_BODY_TDD                              "TDD"
#define XINAN_MESSAGE_BODY_DUPLEX                           "DUPLEX"

#define XINAN_MESSAGE_BODY_LTE                              "LTE"
#define XINAN_MESSAGE_BODY_GSM                              "GSM"
#define XINAN_MESSAGE_BODY_WCDMA                            "WCDMA"
#define XINAN_MESSAGE_BODY_TYPE                             "TYPE"
#define XINAN_MESSAGE_BODY_IDX                              "IDX"
#define XINAN_MESSAGE_BODY_0                                "0"
#define XINAN_MESSAGE_BODY_1                                "1"
#define XINAN_MESSAGE_BODY_2                                "2"
#define XINAN_MESSAGE_BODY_3                                "3"
#define XINAN_MESSAGE_BODY_4                                "4"
#define XINAN_MESSAGE_BODY_5                                "5"
#define XINAN_MESSAGE_BODY_6                                "6"
#define XINAN_MESSAGE_BODY_7                                "7"
#define XINAN_MESSAGE_BODY_8                                "8"
#define XINAN_MESSAGE_BODY_9                                "9"

#define XINAN_MESSAGE_BODY_BSIC                             "BSIC"
#define XINAN_MESSAGE_BODY_C1                               "C1"
#define XINAN_MESSAGE_BODY_C2                               "C2"
#define XINAN_MESSAGE_BODY_RSSI                             "RSSI"



#ifdef __cplusplus
extern "C" {
#endif

typedef void (*PROTOCOL_HANDLER)(const char* ,ssize_t, char*, int*);
typedef struct /*_PROTOCOL_HANDLER*/ 
{	
	const char*       header;	
	PROTOCOL_HANDLER  handler;
} HANDLER;

typedef enum {
    XINAN_SERVER_IDLE,
    XINAN_SERVER_CONNECTING,
	XINAN_SERVER_CONNECTED
} xinAnServerState_t;

typedef struct
{
    const char*       ie;  //information element
}informationElement;

typedef struct _value_string {
	I32 		 value;
	const char	 *strptr;
} value_string;


void handleMsgFromXinanServer(const char* buf, ssize_t len, char* input, int *inLen);
void sendMsgToXinAnServer(const char* buf, ssize_t len, char* output, int * outlen);

#ifdef __cplusplus
}
#endif
#endif  //_EXTERNALMSG4XA_

